//
//  GradientColor.m
//  MyFunctionDemo
//
//  Created by Ting Han on 2017/9/1.
//  Copyright © 2017年 Ting Han. All rights reserved.
//

#import "GradientColor.h"

@interface GradientColor ()

@property (nonatomic)CGGradientRef gradientRef;

@end

@implementation GradientColor

+ (instancetype)gradientColorWithLocations:(CGFloat [])locations components:(CGFloat [])components count:(size_t)count{
    GradientColor *color = [[[self class]alloc]init];
    color.locations = locations;
    color.components = components;
    color.count = count;
    [color createCGGradient];
    
    return color;
}
- (void)createCGGradient{
    CGColorSpaceRef colorRef = CGColorSpaceCreateDeviceRGB();
    self.gradientRef = CGGradientCreateWithColorComponents(colorRef, self.components, self.locations, self.count);
    CGColorSpaceRelease(colorRef);
    
}

- (void)dealloc{
    CGGradientRelease(self.gradientRef);
}

@end
